package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.R;
import entity.salary.Social;
import entity.salary.dto.InsuranceDto;
import entity.salary.dto.accumulationDto;
import entity.salary.dto.socialDto;
import entity.salary.vo.socialDetailedVo;
import entity.salary.vo.socialVo;
import entity.staff.dto.saveAccountDto;
import entity.staff.dto.withSocialPerDto;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.buba.service.SocialService;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.PageResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-14
 */
@RestController
@RequestMapping("/social")
public class SocialController {

    @Resource
    private SocialService socialService;

    /* *
     * @Author: beisheng
     * @Descriprion: 根据选择的社保方案查询缴费明细
     * @Date: 2023/3/20 19:55
     * @Return: common.R
     * @Param: [socilaId]
     */

    @GetMapping("/socialDetailed/{socilaId}")
    public R socialDetailed(@PathVariable("socilaId") Integer socilaId){
        List<socialDetailedVo> socialDetailedVos = socialService.socialDetailed(socilaId);
        return R.success(socialDetailedVos);
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 修改社保方案及公积金方案配置信息及关联人员
     * @Date: 2023/3/17 11:21
     * @Return: common.R
     * @Param: [insuranceDto]
     */

    @PostMapping("/updateSocial")
    public R updateSocial(@RequestBody InsuranceDto insuranceDto){
        socialService.updateSocial(insuranceDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 更改社保方案状态
     * @Date: 2023/3/17 10:43
     * @Return: common.R
     * @Param: [id]
     */

    @PostMapping("/updateSocialStatus")
    public R updateSocialStatus(@RequestBody Map<String,Object> map){
        socialService.updateSocialStatus(map);
        return R.success();
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 添加人员到社保方案
     * @Date: 2023/3/17 9:52
     * @Return: common.R
     * @Param: [saveAccountDto]
     */

    @PostMapping("/saveAccuntToSocial")
    public R saveAccuntToSocial(@RequestBody saveAccountDto saveAccountDto){
        socialService.saveAccuntToSocial(saveAccountDto);
        return R.success();
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 添加社保方案
     * @Date: 2023/3/16 18:31
     * @Return: common.R
     * @Param: [insuranceDto]
     */

    @PostMapping("/insertSocial")
    public R insertSocial(@RequestBody InsuranceDto insuranceDto){
        socialService.insertSocial(insuranceDto);
        return R.success();
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 分页查询社保方案
     * @Date: 2023/3/15 19:00
     * @Return: common.R
     * @Param: []
     */

    @PostMapping("/findAllSocial")
    public R findAllSocial(@RequestBody socialDto socialDto){
        PageResult socialVos = socialService.findAllSocial(socialDto);
        return R.success(socialVos);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据社保方案ID查询当前社保方案关联的人员信息
     * @Date: 2023/3/16 10:47
     * @Return: common.R
     * @Param: [socialPerDto]
     */

    @PostMapping("/findWithSocialPer")
    public R findAllSocial(@RequestBody withSocialPerDto socialPerDto){
        PageResult withSocialPerDto = socialService.withSocialPerDto(socialPerDto);
        return R.success(withSocialPerDto);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 判断方案是否存在
     * @Date: 2023/3/16 15:29
     * @Return: common.R
     * @Param: [schemeName]
     */

    @GetMapping("/judgeScheme")
    public R judgeScheme(@RequestParam String schemeName){
        boolean b = socialService.judgeScheme(schemeName);
        return R.success(b);
    }
    /**
     * 功能描述: 新增或更新
     *
     * @param social
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/save")
    public R save(@RequestBody Social social) {
        socialService.saveOrUpdate(social);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 删除方案,并删除关联方案配置信息
     * @Date: 2023/3/17 10:26
     * @Return: common.R
     * @Param: [id]
     */

    @GetMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        socialService.removeSocial(id);
        return R.success();
    }

   /* *
    * @Author: beisheng
    * @Descriprion: 批量删除方案,并删除关联方案信息
    * @Date: 2023/3/17 10:29
    * @Return: common.R
    * @Param: [ids]
    */

    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        return socialService.removeSocialByIds(ids);
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(socialService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(socialService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: zl
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<Social> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(socialService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据社保ID查询关联人员和关联险种信息
     * @Date: 2023/4/6 10:47
     * @Return: common.R
     * @Param: [socialId]
     */

    @GetMapping("/selSocialAndPeopleAndSocialFile/{socialId}")
    public R selSocialAndPeopleAndSocialFile(@PathVariable("socialId") Integer socialId){
        accumulationDto  accumulationDto =  socialService.selSocialAndPeopleAndSocialFile(socialId);
        return R.success(accumulationDto);

    }

}
